﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Web;


namespace Service.Impl
{
    public class UserManager : ManagerBase<User>, IUserManager
    {
        public User Connexion(string email, string password)
        {
            var user = Repos.GetQueryable<User>().Where(x => x.Email == email)
                   .Where(x => x.Password == password).FirstOrDefault();
            return user;

            
        }

        public string ConvertSha(string password)
        {
            SHA256 sha = SHA256.Create();
            byte[] data = sha.ComputeHash(Encoding.Default.GetBytes(password));
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sb.Append(data[i].ToString("x2"));
            }
            return sb.ToString();
        }

        public IEnumerable<User> GetAllOrderByRoleAndName()
        {
            return Repos.GetQueryable<User>().OrderBy(x => x.Role).OrderBy(x => x.Name);
        }

    }
}
